package com.wwj.admin.statistics.controller;

import com.github.pagehelper.Page;
import com.wwj.core.wawa.entity.WaWaMachineStatistics;
import com.wwj.core.wawa.service.IWaWaMachineStatisticsService;
import com.wwj.framework.controller.BaseController;
import com.wwj.framework.utils.Page2EasyUiData;
import com.wwj.framework.utils.ReturnData;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("statistics")
public class StatisticsController extends BaseController {
    private final String SINGLE = "/admin/statistics/single";
    private final String TOTAL = "/admin/statistics/all";

    @Resource
    private IWaWaMachineStatisticsService waWaMachineStatisticsService;

    @RequestMapping(value = {"/single","/single/","/single/index"})
    public String single() {
        return SINGLE;
    }

    @RequestMapping(value = {"/all","/all/","/all/index"})
    public String total() {
        return TOTAL;
    }

    @RequestMapping("/single_day/listData.json")
    @ResponseBody
    public ReturnData listSingleDay(String singleDayStartDate,String singleDayEndDate, String search, int offset, int limit)throws Exception{
        Map<String,Object> params = new HashMap<String,Object>();
        if(null != search && !"".equals(search)) {
            search = new String(search.getBytes("ISO8859-1"), "UTF-8");
            params.put("search",search);
        }
        if(null != singleDayStartDate && !"".equals(singleDayStartDate)) params.put("startDate",singleDayStartDate);
        if(null != singleDayEndDate && !"".equals(singleDayEndDate)) params.put("endDate", singleDayEndDate);

        Page<WaWaMachineStatistics> WaWaMachineStatistics = waWaMachineStatisticsService.findSingleDayByPage(params, offset, limit);
        return new ReturnData().success(Page2EasyUiData.format(WaWaMachineStatistics));
    }

    @RequestMapping("/single_total/listData.json")
    @ResponseBody
    public ReturnData listSingleTotal(String singleTotalStartDate, String singleTotalEndDate, String search, int offset, int limit)throws Exception{
        Map<String,Object> params = new HashMap<String,Object>();
        if(null != search && !"".equals(search)) {
            search = new String(search.getBytes("ISO8859-1"), "UTF-8");
            params.put("search",search);
        }
        if(null != singleTotalStartDate && !"".equals(singleTotalStartDate)) params.put("startDate",singleTotalStartDate);
        if(null != singleTotalEndDate && !"".equals(singleTotalEndDate)) params.put("endDate",singleTotalEndDate);

        Page<WaWaMachineStatistics> WaWaMachineStatistics = waWaMachineStatisticsService.findSingleTotalByPage(params, offset, limit);
        return new ReturnData().success(Page2EasyUiData.format(WaWaMachineStatistics));
    }

    @RequestMapping("/all_day/listData.json")
    @ResponseBody
    public ReturnData listAllDay(String allDayStartDate,String allDayEndDate, String search, int offset, int limit)throws Exception{
        Map<String,Object> params = new HashMap<String,Object>();
        if(null != search && !"".equals(search)) {
            search = new String(search.getBytes("ISO8859-1"), "UTF-8");
            params.put("search",search);
        }
        if(null != allDayStartDate && !"".equals(allDayStartDate)) params.put("startDate",allDayStartDate);
        if(null != allDayEndDate && !"".equals(allDayEndDate)) params.put("endDate",allDayEndDate);
        Page<WaWaMachineStatistics> WaWaMachineStatistics = waWaMachineStatisticsService.findAllDayByPage(params, offset, limit);
        return new ReturnData().success(Page2EasyUiData.format(WaWaMachineStatistics));
    }

    @RequestMapping("/all_total/listData.json")
    @ResponseBody
    public ReturnData listAllTotal(String allTotalStartDate,String allTotalEndDate, String search, int offset, int limit)throws Exception{
        Map<String,Object> params = new HashMap<String,Object>();
        if(null != search && !"".equals(search)) {
            search = new String(search.getBytes("ISO8859-1"), "UTF-8");
            params.put("search",search);
        }
        if(null != allTotalStartDate && !"".equals(allTotalStartDate)) params.put("startDate",allTotalStartDate);
        if(null != allTotalEndDate && !"".equals(allTotalEndDate)) params.put("endDate",allTotalEndDate);
        Page<WaWaMachineStatistics> WaWaMachineStatistics = waWaMachineStatisticsService.findAllTotalByPage(params, offset, limit);
        return new ReturnData().success(Page2EasyUiData.format(WaWaMachineStatistics));
    }
}
